package com.zc.topmod.controller;

import com.zc.topmod.entity.TopModCalReqBO;
import com.zc.topmod.entity.TopModCalRspBO;
import com.zc.topmod.impl.BaseRebModCalFormulaImpl;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;

@Controller
@RequestMapping("/zc")
@Slf4j
public class CommonController {

    @RequestMapping("/jsp/topmod")
    public String home() {
        return "views/topmod";
    }

    @RequestMapping("/jsp/topmod3")
    public String home2() {
        return "views/topmod3";
    }

    @RequestMapping(value="/api/topmodcal.do",method = RequestMethod.POST)
    public @ResponseBody TopModCalRspBO topModCal(@RequestBody TopModCalReqBO topModCalReqBO) {

        log.info("开始计算处理");
        BaseRebModCalFormulaImpl baseRebModCalFormulaImpl =new BaseRebModCalFormulaImpl();
        TopModCalRspBO topModCalRspBO=new TopModCalRspBO();

        log.info("打印请求字段"+topModCalReqBO.toString());

        log.info("计算Et");
        Double et=baseRebModCalFormulaImpl.calForm(topModCalReqBO.getSurfaceThickness(),topModCalReqBO.getSurfaceModulus(),topModCalReqBO.getFrequency());
        log.info("Et:"+et);
        topModCalRspBO.setReboundModMeaVal(et);

        log.info("计算S0");
        Double s0=0.00;
        if (!topModCalReqBO.getDeflection().isNaN()&&Double.compare(topModCalReqBO.getDeflection(),0.00)>0) {
            s0=baseRebModCalFormulaImpl.calFormWc(topModCalReqBO.getDisOutTireEnum(),topModCalReqBO.getDeflection());
        } else {
            s0=baseRebModCalFormulaImpl.calFormYb(topModCalReqBO.getDisOutTireEnum(),et,topModCalReqBO.getStrain());
        }
        log.info("s0:"+s0);

        log.info("计算S静");
        Double jwc=baseRebModCalFormulaImpl.calFormJwc(s0,topModCalReqBO.getRoadFlatness(),topModCalReqBO.getDrivingSpeed());
        log.info("jwc:"+jwc);

        log.info("计算SSI");
        Double ssi=baseRebModCalFormulaImpl.calFormSsi(topModCalReqBO.getDesignAllowDef(),jwc);
        log.info("ssi:"+ssi);
        topModCalRspBO.setSSI(ssi);

        log.info("计算PSSI");
        Double pssi=baseRebModCalFormulaImpl.calFormPssi(ssi);
        log.info("pssi:"+pssi);
        topModCalRspBO.setPSSI(pssi);

        log.info("计算SSI道路等级");
        String roadssievalevel=baseRebModCalFormulaImpl.judgeSsiRoadEvaLevel(topModCalReqBO.getRoadGradeEnum(),ssi);
        log.info("roadssievalevel:"+roadssievalevel);
        topModCalRspBO.setRoadSsiEvaLevelEnum(roadssievalevel);

        log.info("计算PSSI道路等级");
        String roadpssievalevel=baseRebModCalFormulaImpl.judgePssiRoadEvaLevel(topModCalReqBO.getRoadGradeEnum(),pssi);
        log.info("roadpssievalevel:"+roadpssievalevel);
        topModCalRspBO.setRoadPssiEvaLevelEnum(roadpssievalevel);

        log.info("topModCalRspBO:"+topModCalRspBO.toString());

        return topModCalRspBO;
    }
}